import string
import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
import allure
# from code_cv import read_code
import random
driver = webdriver.Chrome()

driver.get("http://novel-admin.hctestedu.com/index")

WebDriverWait(driver,10).until(ec.visibility_of_element_located((By.NAME,'username'))).send_keys("测试权限账号")
WebDriverWait(driver,10).until(ec.visibility_of_element_located((By.NAME,'password'))).send_keys("ceshiquanxianzhanghao")

# element = driver.find_element(By.ID,'imgVerify')
# element.screenshot("code.png")
# time.sleep(3)
# code = read_code()
# driver.find_element(By.NAME,'verify').send_keys(code)
while True:
    if input()=='ok':
        break
WebDriverWait(driver,10).until(ec.visibility_of_element_located((By.ID,'login'))).click()
WebDriverWait(driver,10).until(ec.visibility_of_element_located((By.LINK_TEXT,'作家管理'))).click()
WebDriverWait(driver,10).until(ec.visibility_of_element_located((By.LINK_TEXT,'邀请码管理'))).click()

frames = driver.find_elements(By.TAG_NAME,'iframe')
driver.switch_to.frame(frames[-1])
WebDriverWait(driver,10).until(ec.visibility_of_element_located((By.CLASS_NAME,'btn'))).click()

frames1 = driver.find_elements(By.TAG_NAME,'iframe')
driver.switch_to.frame(frames1[-1])
activate_code = ''.join(random.choices(string.digits,k=5))
WebDriverWait(driver,10).until(ec.visibility_of_element_located((By.ID,'inviteCode'))).send_keys(activate_code)

WebDriverWait(driver,10).until(ec.visibility_of_element_located((By.XPATH,'//*[@id="validityTime"]'))).click()
WebDriverWait(driver,10).until(ec.visibility_of_element_located((By.XPATH,'//*[@id="laydate_table"]/tbody/tr[3]/td[3]'))).click()

WebDriverWait(driver,10).until(ec.visibility_of_element_located((By.CLASS_NAME,'btn'))).click()

time.sleep(10)

